
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 08/04/2014 22:41:37
-- Generated from EDMX file: D:\YandexDisk\1\Projects\project-experimental8\Experimental8.Common.Data\EDM\Experimental8Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Experimental8];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[fk_contractor_store]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[storeSet] DROP CONSTRAINT [fk_contractor_store];
GO
IF OBJECT_ID(N'[dbo].[fk_contractor_contractor_2_contractor_group]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[contractor_2_contractor_groupSet] DROP CONSTRAINT [fk_contractor_contractor_2_contractor_group];
GO
IF OBJECT_ID(N'[dbo].[fk_contractor_group_contractor_2_contractor_group]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[contractor_2_contractor_groupSet] DROP CONSTRAINT [fk_contractor_group_contractor_2_contractor_group];
GO
IF OBJECT_ID(N'[dbo].[fk_ui_fields_propertyui_fields_property_item]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ui_fields_property_itemSet] DROP CONSTRAINT [fk_ui_fields_propertyui_fields_property_item];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[contractorSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[contractorSet];
GO
IF OBJECT_ID(N'[dbo].[storeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[storeSet];
GO
IF OBJECT_ID(N'[dbo].[contractor_groupSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[contractor_groupSet];
GO
IF OBJECT_ID(N'[dbo].[contractor_2_contractor_groupSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[contractor_2_contractor_groupSet];
GO
IF OBJECT_ID(N'[dbo].[ui_fields_propertySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ui_fields_propertySet];
GO
IF OBJECT_ID(N'[dbo].[ui_fields_property_itemSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ui_fields_property_itemSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'contractorSet'
CREATE TABLE [dbo].[contractorSet] (
    [id_contractor_global] uniqueidentifier  NOT NULL,
    [name] nvarchar(100)  NOT NULL,
    [full_name] nvarchar(1000)  NULL,
    [inn] nvarchar(20)  NULL,
    [address] nvarchar(1000)  NULL,
    [phone] nvarchar(255)  NULL,
    [okpo] nvarchar(10)  NULL,
    [okonh] nvarchar(20)  NULL,
    [kpp] nvarchar(10)  NULL,
    [email] nvarchar(255)  NULL,
    [bank] nvarchar(100)  NULL,
    [bank_correspond] nvarchar(50)  NULL,
    [account] nvarchar(50)  NULL,
    [bank_address] nvarchar(100)  NULL,
    [corr_account] nvarchar(20)  NULL,
    [bik] nvarchar(10)  NULL,
    [fo_ogrn] nvarchar(15)  NULL,
    [director_fio] nvarchar(255)  NULL,
    [buh_fio] nvarchar(255)  NULL,
    [ur_address] nvarchar(255)  NULL,
    [is_filial] bit  NULL,
    [date_modified] datetime  NULL,
    [date_inserted] datetime  NULL,
    [date_deleted] datetime  NULL,
    [mnemocode] nvarchar(4)  NULL
);
GO

-- Creating table 'storeSet'
CREATE TABLE [dbo].[storeSet] (
    [id_store_global] uniqueidentifier  NOT NULL,
    [name] nvarchar(100)  NULL,
    [id_contractor_global] uniqueidentifier  NOT NULL,
    [mnemocode] nvarchar(40)  NULL,
    [id_pricing_model_global] uniqueidentifier  NOT NULL,
    [date_modified] datetime  NULL,
    [date_inserted] datetime  NULL,
    [date_deleted] datetime  NULL,
    [contractor_id_contractor_global] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'contractor_groupSet'
CREATE TABLE [dbo].[contractor_groupSet] (
    [id_contractor_group_global] uniqueidentifier  NOT NULL,
    [name] nvarchar(100)  NOT NULL,
    [id_contractor_group_parent] uniqueidentifier  NULL,
    [description] nvarchar(500)  NOT NULL,
    [date_modified] datetime  NULL,
    [date_inserted] datetime  NULL,
    [date_deleted] datetime  NULL,
    [is_system] bit  NULL
);
GO

-- Creating table 'contractor_2_contractor_groupSet'
CREATE TABLE [dbo].[contractor_2_contractor_groupSet] (
    [id_contractor_2_contractor_group_global] uniqueidentifier  NOT NULL,
    [id_contractor_global] uniqueidentifier  NOT NULL,
    [id_contractor_group_global] uniqueidentifier  NOT NULL,
    [contractors_id_contractor_global] uniqueidentifier  NOT NULL,
    [contractor_groups_id_contractor_group_global] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'ui_fields_informationSet'
CREATE TABLE [dbo].[ui_fields_informationSet] (
    [id_ui_fields_information_global] uniqueidentifier  NOT NULL,
    [code] varchar(40)  NOT NULL,
    [name] nvarchar(40)  NULL
);
GO

-- Creating table 'ui_fields_information_itemSet'
CREATE TABLE [dbo].[ui_fields_information_itemSet] (
    [id_ui_fields_information_item_global] uniqueidentifier  NOT NULL,
    [id_ui_fields_information_global] uniqueidentifier  NOT NULL,
    [code] varchar(40)  NOT NULL,
    [name] nvarchar(40)  NULL,
    [order] smallint  NULL,
    [width] smallint  NULL,
    [binding_field_name] varchar(max)  NULL,
    [visible] bit  NULL,
    [read_only] bit  NULL,
    [ui_fields_information_id_ui_fields_information_global] uniqueidentifier  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [id_contractor_global] in table 'contractorSet'
ALTER TABLE [dbo].[contractorSet]
ADD CONSTRAINT [PK_contractorSet]
    PRIMARY KEY CLUSTERED ([id_contractor_global] ASC);
GO

-- Creating primary key on [id_store_global] in table 'storeSet'
ALTER TABLE [dbo].[storeSet]
ADD CONSTRAINT [PK_storeSet]
    PRIMARY KEY CLUSTERED ([id_store_global] ASC);
GO

-- Creating primary key on [id_contractor_group_global] in table 'contractor_groupSet'
ALTER TABLE [dbo].[contractor_groupSet]
ADD CONSTRAINT [PK_contractor_groupSet]
    PRIMARY KEY CLUSTERED ([id_contractor_group_global] ASC);
GO

-- Creating primary key on [id_contractor_2_contractor_group_global] in table 'contractor_2_contractor_groupSet'
ALTER TABLE [dbo].[contractor_2_contractor_groupSet]
ADD CONSTRAINT [PK_contractor_2_contractor_groupSet]
    PRIMARY KEY CLUSTERED ([id_contractor_2_contractor_group_global] ASC);
GO

-- Creating primary key on [id_ui_fields_information_global] in table 'ui_fields_informationSet'
ALTER TABLE [dbo].[ui_fields_informationSet]
ADD CONSTRAINT [PK_ui_fields_informationSet]
    PRIMARY KEY CLUSTERED ([id_ui_fields_information_global] ASC);
GO

-- Creating primary key on [id_ui_fields_information_item_global] in table 'ui_fields_information_itemSet'
ALTER TABLE [dbo].[ui_fields_information_itemSet]
ADD CONSTRAINT [PK_ui_fields_information_itemSet]
    PRIMARY KEY CLUSTERED ([id_ui_fields_information_item_global] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [contractor_id_contractor_global] in table 'storeSet'
ALTER TABLE [dbo].[storeSet]
ADD CONSTRAINT [fk_contractor_store]
    FOREIGN KEY ([contractor_id_contractor_global])
    REFERENCES [dbo].[contractorSet]
        ([id_contractor_global])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'fk_contractor_store'
CREATE INDEX [IX_fk_contractor_store]
ON [dbo].[storeSet]
    ([contractor_id_contractor_global]);
GO

-- Creating foreign key on [contractors_id_contractor_global] in table 'contractor_2_contractor_groupSet'
ALTER TABLE [dbo].[contractor_2_contractor_groupSet]
ADD CONSTRAINT [fk_contractor_contractor_2_contractor_group]
    FOREIGN KEY ([contractors_id_contractor_global])
    REFERENCES [dbo].[contractorSet]
        ([id_contractor_global])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'fk_contractor_contractor_2_contractor_group'
CREATE INDEX [IX_fk_contractor_contractor_2_contractor_group]
ON [dbo].[contractor_2_contractor_groupSet]
    ([contractors_id_contractor_global]);
GO

-- Creating foreign key on [contractor_groups_id_contractor_group_global] in table 'contractor_2_contractor_groupSet'
ALTER TABLE [dbo].[contractor_2_contractor_groupSet]
ADD CONSTRAINT [fk_contractor_group_contractor_2_contractor_group]
    FOREIGN KEY ([contractor_groups_id_contractor_group_global])
    REFERENCES [dbo].[contractor_groupSet]
        ([id_contractor_group_global])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'fk_contractor_group_contractor_2_contractor_group'
CREATE INDEX [IX_fk_contractor_group_contractor_2_contractor_group]
ON [dbo].[contractor_2_contractor_groupSet]
    ([contractor_groups_id_contractor_group_global]);
GO

-- Creating foreign key on [ui_fields_information_id_ui_fields_information_global] in table 'ui_fields_information_itemSet'
ALTER TABLE [dbo].[ui_fields_information_itemSet]
ADD CONSTRAINT [fk_ui_fields_informationui_fields_information_item]
    FOREIGN KEY ([ui_fields_information_id_ui_fields_information_global])
    REFERENCES [dbo].[ui_fields_informationSet]
        ([id_ui_fields_information_global])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'fk_ui_fields_informationui_fields_information_item'
CREATE INDEX [IX_fk_ui_fields_informationui_fields_information_item]
ON [dbo].[ui_fields_information_itemSet]
    ([ui_fields_information_id_ui_fields_information_global]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------